package com.budwk.app.common.component;

import com.budwk.app.sqfw.constants.DictConstants;
import com.budwk.app.sys.models.Sys_dict;
import com.budwk.app.sys.services.SysDictService;
import com.budwk.app.sys.vo.SysDictVO;
import com.budwk.app.util.poiUtils.nutzBeanUtils.NutzIocUtils;
import org.apache.commons.lang3.StringUtils;
import org.nutz.dao.Cnd;

import java.util.ArrayList;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

public class DictComponent {

    public static Map<String, String> INDUSTY_SECTOR_TYPES_MAP() {
        // 1 从数据字典中获取
        SysDictService dictService = NutzIocUtils.getBean(SysDictService.class);
        List<SysDictVO> dictVOS = dictService.listDictByCode(DictConstants.INDUSTY_SECTOR_TYPES);
        Map<String, String> map = dictVOS.stream().collect(Collectors.toMap(SysDictVO::getCode, SysDictVO::getName));
        // 2 以下不在数据字典中
        map.put(DictConstants.INDUSTY_SECTOR_HOTEL, "旅馆");
        map.put(DictConstants.INDUSTY_SECTOR_EDUCATION, "教育培训");
        map.put(DictConstants.INDUSTY_SECTOR_MEDICAL, "医疗");
        map.put(DictConstants.INDUSTY_SECTOR_FOOT, "美容足疗洗浴按摩");
        map.put(DictConstants.INDUSTY_SECTOR_RESTAU, "餐饮");
        return map;
    }

    public static List<String> getResidentNoForms() {
        return List.of(DictConstants.RESIDENTS_FORM_STAY_STORE, DictConstants.RESIDENTS_FORM_IN_AND_OUT, DictConstants.RESIDENTS_FORM_DWELLING, DictConstants.RESIDENTS_FORM_OTHER);
    }

    public static List<String> GAS_USAGE_LIST() {
        List<String> list = new ArrayList<>();
        list.add("gas_usage_methanol"); // 甲醇
        list.add("gas_usage_ethanol"); //乙醇
        list.add("gas_usage_propanol"); //丙醇
        list.add("gas_usage_butane"); //丁烷
        list.add("gas_usage_diesel_oil"); //柴油
        list.add("gas_usage_white_oil"); //白油
        list.add("gas_usage_butter"); //黄油
        list.add("gas_usage_vegetable_oil"); //植物油
        list.add("gas_usage_environment_friendly_oil"); //环保油
        list.add("gas_usage_electricity_consumption"); //用电
        list.add("gas_usage_other_fuels"); //其他燃油
        return list;
    }

    public static List<String> electricalCircuitSituationList() {
        // 存在问题的电气线路情况
        return List.of(DictConstants.ELECTRICAL_CIRCUIT_CONSUMPTION, DictConstants.ELECTRICAL_CIRCUIT_RANDOMLY,
                DictConstants.ELECTRICAL_CIRCUIT_PRODUCTS, DictConstants.ELECTRICAL_CIRCUIT_OTHER);
    }

    public static List<String> listFireGasCode() {
        // 状态中包含了【瓶装液化气】、【瓶装天然气】、【瓶装二甲醚】三项任意一项时，生成文档。
        List<String> list = new ArrayList<>();
        list.add(DictConstants.BOTTLED_GAS);
        list.add(DictConstants.NATURAL_GAS);
        list.add(DictConstants.BOTTLED_ETHER);
        return list;
    }

    // 有重孙级的字典code
    public static List<String> getGrandchildCode() {
        return List.of(DictConstants.MAIN_BUSINESS_SCOPE, DictConstants.RESIDENTS_TYPES, DictConstants.HOUSEHOLDS, DictConstants.BELONG_INDUS);
    }

    public static String getDictName(String dictCode, String value) {
        if (StringUtils.isNotBlank(value)) {
            return value;
        }
        if (StringUtils.isEmpty(dictCode)) {
            return StringUtils.EMPTY;
        }
        SysDictService sysDictService = NutzIocUtils.getBean(SysDictService.class);
        Sys_dict dict = sysDictService.fetch(Cnd.where(Sys_dict::getCode, "=", dictCode));
        if (dict == null) {
            return StringUtils.EMPTY;
        }
        return dict.getName();
    }

    public static List<SysDictVO> getSpecialPersonnelTypes() {
        SysDictService sysDictService = (SysDictService) NutzIocUtils.getBeanByType(SysDictService.class);
        return sysDictService.listDictByCode(DictConstants.SPECIAL_PERSONNEL_TYPES);
    }

    // 特殊人员体：【弱】【病】【残】【酒】【疯】【单独居老人】及【双独居老人】 作为导出台账使用
    public static Map<String, String> specialMarks() {
        Map<String, String> map = new LinkedHashMap<>();
        map.put("oldAlone", "单独居老人");
        map.put("oldMany", "双独居老人");
        map.put("weak", "弱");
        map.put("sick", "病");
        map.put("incomplete", "残");
        map.put("win", "酒");
        map.put("mad", "疯");
        return map;
    }

    public static List<String> listGas() {
        List<String> list = new ArrayList<>();
        list.add(DictConstants.BOTTLED_GAS);
        list.add(DictConstants.NATURAL_GAS);
        list.add(DictConstants.BOTTLED_ETHER);
        list.add(DictConstants.BOTTLED_ETHER_ELECTRICITY);
        list.add(DictConstants.BOTTLED_ETHER_ELECTRICITY_GAS);
        return list;
    }

    public static List<String> MAIN_BUSINESS_SCOPE_SAFETY_LIST() {
        List<String> list = new ArrayList<>();
        list.add("large_shopping_malls_supermarkets_hotels");
        list.add("boarding_schools_social_welfare_institutions");
        list.add("hospitals_clinics_health_service_stations");
        list.add("enterprises_operation_venues_formats");
        list.add("other_key_fire_safety_sites");
        return list;
    }

}
